package com.qdu.servlet;

import com.qdu.entity.Movie;
import com.qdu.service.CommentService;
import com.qdu.service.MovieService;
import com.qdu.service.impl.CommentServiceImpl;
import com.qdu.service.impl.MovieServiceImpl;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 根据电影编号查询单个电影所有信息的Servlet
 *
 * @author Anna
 */
@WebServlet("/gmis")
public class GetMovieInfoServlet extends HttpServlet {

    MovieService movieService = new MovieServiceImpl();
    CommentService commentService = new CommentServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1. 获取请求参数
        //获取提交的电影编号
        String movieId = req.getParameter("movieId");

        //
        String mbid = req.getParameter("movieId");
        List<Object[]> commentList = commentService.findCommentListByMBId(mbid);
        HttpSession session = req.getSession();
        session.setAttribute("commentList", commentList);
        //

        //2. 执行业务逻辑 
        //调用MovieService类的findMovieById()方法根据电影编号查询电影所有信息
        Movie movie = movieService.findMovieById(movieId);

        //3. 生成动态响应
        //将查到的Movie对象作为属性放入请求对象，转发请求共享给movie_info.jsp页面显示电影信息
        req.setAttribute("movie", movie);
        req.getRequestDispatcher("/movie_info2.jsp").forward(req, resp);
    }
}
